_human = _this select 0;

_trg=createTrigger[ "EmptyDetector",(getPos _human)]; 
_trg setTriggerArea[50,50,0,false];
_trg setTriggerActivation["CIV","PRESENT",true];
_trg setTriggerStatements["this", "", ""]; 


// add to the human to the list of array 
CivilsDetectingThisHuman=[];
CivilsDetectingHumans=CivilsDetectingHumans+[[_human,CivilsDetectingThisHuman]];

_civilsKnowing=[];
_civilsKnowingTime=[];
_civilKnowingTooFar=[];
while { true } do
{		
	
	_markers=[];

	_trg setPos (getPos _human);
	
	sleep 0.1;
    
    
	// get the list of civil already knowing but too far from the human
     _civilKnowingTooFar=_civilsKnowing-(list _trg);
    
	
	// remove all entry for civil too far (in the knowingTime array and civils array)
	
    { // foreach civil too far
	
            _idx=(_civilsKnowing find _x);

			_civilsKnowingTime set [_idx,nil];
			_tmp=[];
			
			for [{_c=0},{_c<(count _civilsKnowingTime)},{_c=_c+1}]  do
			{
				if(_c!=_idx) then
				{
					_tmp=_tmp+[_civilsKnowingTime select _c];
				};
			};

			_civilsKnowingTime=_tmp;

            _civilsKnowing=_civilsKnowing-[_x];

            CivilsDetectingThisHuman=CivilsDetectingThisHuman-[_x];

    } forEach _civilKnowingTooFar;

	
	// if there are civils in the trigger list
	if( (count list _trg) > 0 ) then {
				       
		// then check for civil knowing...
		
		{ // forEach civil found

			_civil = _x;
						
			// if the civil knows enought the human
			if( (_civil knowsAbout  _human) > 0.7) then {
	
				// and if civil already in the knowing list
				if(_civil in _civilsKnowing) then {
					
					_civilArrayPos=_civilsKnowing find _civil;
					_civilKnowingTime=(_civilsKnowingTime select _civilArrayPos);

					// if the duration since the first knowing is > now 
					if((time-_civilKnowingTime)>CivilDetectionDuration)then{

						// we show the civil on the map
						_civMarker=createMarkerLocal [ (format["%1",_civil]) , (getPos _civil) ];
						_civMarker setMarkerShapeLocal "ICON";
						_civMarker setMarkerTypeLocal "DOT";
						_civMarker setMarkerColorLocal "ColorRed";
						_civMarker setMarkerPosLocal (getPos _civil);
						_markers=_markers+[_civMarker];

						// if not already in the global detected list, then add it
						if(!(_civil in CivilsDetectingThisHuman)) then {
								CivilsDetectingThisHuman=CivilsDetectingThisHuman+[_civil];
						};
					};
	
				}else{ 

					// its the first time this civil know the human so we save the time
					_civilsKnowing= _civilsKnowing+[_civil];	
					_civilsKnowingTime= _civilsKnowingTime+[time];

				};

			}
			else
			{
				
				// the civil dont know enought about the human => delete it in the civil knowing table (if there)
				_civilArrayPos=_civilsKnowing find _civil;

				if(_civilArrayPos > -1) then 
				{
					_civilKnowingTime=_civilsKnowingTime select _civilArrayPos;
		
					_civilsKnowing= _civilsKnowing-[_civil];	
					_civilsKnowingTime= _civilsKnowingTime-[_civilKnowingTime];	
				};

                CivilsDetectingThisHuman=CivilsDetectingThisHuman-[_civil];

			};

		}forEach (list _trg);
	};

	// Update  the human civils global knowing list
	for [{_c=0},{_c<(count CivilsDetectingHumans)},{_c=_c+1}]  do
	{
		if((CivilsDetectingHumans select _c) select 0 == _human)then{
			//player globalChat format["ARRAY POS %1,%2",_c,CivilsDetectingThisHuman ];
			CivilsDetectingHumans set [_c,[_human,CivilsDetectingThisHuman ]];
		};
	 };

	sleep 0.5;
	
	// delete all markers
	{
		deleteMarkerLocal _x;
	}forEach _markers;
	

	
};


	
	

